<script>
	import {
		mapMutations
	} from 'vuex'
	import user from '@/api/user.js'
	export default {
		computed: {
			websocket() {
				return this.$store.state.webSocket.ws
			},
		},
		watch: {
			websocket(newVal) {
				if (newVal) {
					newVal.onmessage = (event) => {
						console.log("接受信息", event.data);
					}
				}
			}
		},
		onLaunch: function() {},
		onShow: function() {
			// 刷新后重新获取登录信息
			let token = sessionStorage.getItem('Token')
			if (token) {
				user.get().then(res => {
					this.SET_ISLOGIN(true)
					this.SET_USERINFO(res.data)
					this.$store.dispatch("startWebSocket");
				})
			}
		},
		onHide: function() {},

		methods: {
			...mapMutations('user', ['SET_USERINFO', 'SET_ISLOGIN'])
		}
	}
</script>

<style lang="scss">
	@import '~@/static/styles/app.scss';
</style>